/**
 * 
 */
package com.antilia.infomaresme.pages;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxCallDecorator;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

/**
 * @author Ernesto
 *
 */
public abstract class RoundSubmitLinkPanel extends Panel {

	private static final long serialVersionUID = 1L;


	/**
	 * @param id
	 */
	public RoundSubmitLinkPanel(String id, IModel<String> model) {
		super(id, model);
		AjaxSubmitLink link = new AjaxSubmitLink("link") {
			
			private static final long serialVersionUID = 1L;

			protected void onError(AjaxRequestTarget target, Form<?> form) {
				RoundSubmitLinkPanel.this.onError(target, form);
			};
			
			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				RoundSubmitLinkPanel.this.onSubmit(target, form);
			}
			
			@Override
			protected IAjaxCallDecorator getAjaxCallDecorator() {
				return RoundSubmitLinkPanel.this.getAjaxCallDecorator();
			}

		};

		add(link);		
		link.add(new Label("title",model)
		.setEscapeModelStrings(false).setRenderBodyOnly(true));
	}
	
	protected IAjaxCallDecorator getAjaxCallDecorator() {
		return null;
	}
	
	protected abstract void onSubmit(AjaxRequestTarget target, Form<?> form);
	
	protected abstract void onError(AjaxRequestTarget target, Form<?> form);

}
